package com.ruoyi.project.config.resources.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.config.resources.domain.ResourcesConfig;
import com.ruoyi.project.config.resources.service.IResourcesConfigService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 资源配置Controller
 * 
 * @author wyh
 * @date 2024-06-17
 */
@RestController
@RequestMapping("/resources/resources")
public class ResourcesConfigController extends BaseController
{
    @Autowired
    private IResourcesConfigService resourcesConfigService;

    /**
     * 查询资源配置列表
     */
    @PreAuthorize("@ss.hasPermi('resources:resources:list')")
    @GetMapping("/list")
    public TableDataInfo list(ResourcesConfig resourcesConfig)
    {
        startPage();
        List<ResourcesConfig> list = resourcesConfigService.selectResourcesConfigList(resourcesConfig);
        return getDataTable(list);
    }

    /**
     * 导出资源配置列表
     */
    @PreAuthorize("@ss.hasPermi('resources:resources:export')")
    @Log(title = "资源配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ResourcesConfig resourcesConfig)
    {
        List<ResourcesConfig> list = resourcesConfigService.selectResourcesConfigList(resourcesConfig);
        ExcelUtil<ResourcesConfig> util = new ExcelUtil<ResourcesConfig>(ResourcesConfig.class);
        util.exportExcel(response, list, "资源配置数据");
    }

    /**
     * 获取资源配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('resources:resources:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(resourcesConfigService.selectResourcesConfigById(id));
    }

    /**
     * 新增资源配置
     */
    @PreAuthorize("@ss.hasPermi('resources:resources:add')")
    @Log(title = "资源配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ResourcesConfig resourcesConfig)
    {
        return toAjax(resourcesConfigService.insertResourcesConfig(resourcesConfig));
    }

    /**
     * 修改资源配置
     */
    @PreAuthorize("@ss.hasPermi('resources:resources:edit')")
    @Log(title = "资源配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ResourcesConfig resourcesConfig)
    {
        return toAjax(resourcesConfigService.updateResourcesConfig(resourcesConfig));
    }

    /**
     * 删除资源配置
     */
    @PreAuthorize("@ss.hasPermi('resources:resources:remove')")
    @Log(title = "资源配置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(resourcesConfigService.deleteResourcesConfigByIds(ids));
    }
}
